<?php 
class Zend_View_Helper_LoggedInUser extends Zend_View_Helper_Abstract
{
	public function loggedInUser(){
		$auth = Zend_Auth::getInstance();
		if($auth->hasIdentity()){
			$username = $auth->getIdentity()->name;
			$status = $auth->getIdentity()->status;
			$logoutUrl = $this->view->url(array('controller' => 'auth', 'action' => 'logout'), 'default', true);
			return 'Welcome ' . $username . '(' . $status . ')' . ' <a href="' . $logoutUrl . '">Logout</a>';
		}
		else{
			$request = Zend_Controller_Front::getInstance()->getRequest();
			$controller = $request->getControllerName();
			$action = $request->getActionName();
			if($controller == 'auth' && $action == 'login'){
				return '';
			}
			else{
				$form = new Application_Form_Login();
				$form->setAction($this->view->url(array('controller' => 'auth', 'action' => 'login'), 'default', true));
				//$form->back->setValue($request->getRequestUri());
				$regUrl = $this->view->url(array('controller' => 'auth', 'action' => 'register'), 'default', true);
				return $form . '<p><a href="' . $regUrl . '">Register</a></p>';				
			} 
		}
	}
}